package mc.contents.web.servlet;
import mc.contents.dao.ShopInfoMapper;
import mc.contents.pojo.persistence.ShopInfo;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by LuoHui on 14-11-26.
 */
@WebServlet(name = "shop4CResponse",urlPatterns="/shop4CResponse",asyncSupported=false)
public class Shop4CResponseServlet extends HttpServlet {
    private ShopInfoMapper shopInfoMapper;

    @Override
    public void init( ServletConfig config ) throws ServletException {
        super.init( config );
        ServletContext servletContext = config.getServletContext();
        WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext( servletContext );
        shopInfoMapper = (ShopInfoMapper) context.getBean( "shopInfoMapper" );
    }

    @Override
    protected void doPost( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
        try{
            String nick = req.getParameter( "nick" );
            String shop4C = req.getParameter( "shop4C" );
            if(StringUtils.isNotEmpty( nick ) && StringUtils.isNotEmpty( shop4C ) && !"undefined".equals( shop4C )){

                ShopInfo shopInfo = shopInfoMapper.getShopInfoByNick( nick );
                shopInfo.setShopService4c( shop4C );
                shopInfoMapper.updateShop4C( nick,shop4C );
            }
        }catch ( Exception e ){
            e.printStackTrace();
        }
    }
}
